import pygame

class CTextureManager(object):
    """ Loads, Retreives and Releases Spritemaps. """
    
    mTextures = {}
        
    @staticmethod    
    def LoadTexture( filename , name ):
        """ Load our texture with a filename and give it a unique reference name. Return a handle to its instance or None. """
        
        # Return null if texture key already exists.
        if( name in CTextureManager.mTextures ):
            return None
        
        # Load in our texture with alpha then return it
        CTextureManager.mTextures[ name ] = pygame.image.load( filename ).convert_alpha()
        return CTextureManager.mTextures[ name ]
    
    @staticmethod
    def GetTexture( name ):
        """ Get a texture from its name. """
        if( name in CTextureManager.mTextures ):
            return CTextureManager.mTextures[name]
        else:
            return None
        
    @staticmethod
    def FreeTexture( name ):
        """ Remove a texture from the manager. """
        
        # Kill reference for GC & Delete Dictionary entry
        CTextureManager[name] = None
        del CTextureManager[name]
        
    @staticmethod
    def IsLoadedTexture( name ):
        """ Get whether or not a texture has been loaded. """
        if( name in CTextureManager.mTextures):
            return True
        else:
            return False
        
    @staticmethod
    def FreeAllTextures():
        """ Free all textures. """
        
        for k in CTextureManager.mTextures.keys():
            CTextureManager.mTextures[k] = None
            del CTextureManager.mTextures[k]
            
        
    
        
        
        
         

